﻿using BLL;
using DAL;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Model;
using NLog.Web;

namespace _11._7WebApI.Controllers
{
    [Route("api/[controller][action]")]
    [ApiController]
    public class LoginController : ControllerBase
    {
        public readonly ILogger<LoginController> _logger;
        public LoginController (LoginBLL loginBLL, ILogger<LoginController> logger)
        {
            _logger = logger;
            LoginBLL = loginBLL;
            
        }
        public LoginBLL LoginBLL { get; }

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="login"></param>
        /// <returns></returns>
        /// 

       [HttpPost]
        public int Add(Login login)
        {
            try
            {
                _logger.LogInformation("添加成功！！");
                return LoginBLL.Add(login);
            }
            catch (Exception)
            {
                _logger.LogInformation("添加失败");
                throw;
            }
        }
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="phone"></param>
        /// <param name="Pwd"></param>
        /// <returns></returns>
        /// 

        [HttpGet]
        public int Login(string phone, string Pwd)
        {
            try
            {
                _logger.LogInformation("登录成功！！");
                return LoginBLL.Login(phone, Pwd);
            }
            catch (Exception)
            {
                _logger.LogInformation("登录成功！！");
                throw;
            }
        }
        /// <summary>
        /// 显示
        /// </summary>
        /// <returns></returns>\
        /// 
        [HttpGet]
        public List<Login> Show()
        {
            try
            {
                _logger.LogInformation("显示成功！！");
                return LoginBLL.Show();
            }
            catch (Exception)
            {
                _logger.LogInformation("显示失败！！");
                throw;
            }
            
        }
        
    }
}
